package com.lt.flashcard.model.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.bson.types.ObjectId;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Reference;
import com.lt.flashcard.model.service.ContentService;
import com.lt.flashcard.model.service.Repository;

/**
 * The category structure for content
 * @author ocsen
 *
 */
@Entity("contentcategory")
public class ContentCategory {

	@Id
	private ObjectId id;
	
	private String name = "";
	
	private Date created = new Date();
	
	@Reference
	private List<ContentCategory> child = new ArrayList<ContentCategory>();
	
	@Reference
	private ContentCategory parent = null;
	
	private int order = 0;
	
	public ObjectId getId() {
		return id;
	}

	public void setId(ObjectId id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public List<ContentCategory> getChild() {
		return child;
	}

	public void setChild(List<ContentCategory> child) {
		this.child = child;
	}

	public ContentCategory getParent() {
		return parent;
	}

	public void setParent(ContentCategory parent) {
		this.parent = parent;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}
	
	public List<Content> getContents() {
		ContentService srv = Repository.getInstance().getContentService();
		return srv.getContentsOfCategory(this);
	}
}
